using UnityEngine;
using System.Collections;

public class PatrollController : MonoBehaviour {

	public float gravity = 20;
	public float movementSpeed = 1;
	
	private Vector2 amountToMove;


	private PatrollPhysics patrollPhysics;

	void Start () {
		patrollPhysics = GetComponent<PatrollPhysics>();

	}
	
	void Update () {

		//this.transform.Translate(Vector3.right * movementSpeed*Time.deltaTime);

		// If patroll is touching the ground
		if (patrollPhysics.grounded) {
			amountToMove.y = 0;

			if (patrollPhysics.IsColided()){
				movementSpeed *= -1;
			}
			if ( patrollPhysics.IsInBorder()){
				patrollPhysics.noBorder();
				movementSpeed *= -1;

			}
		}



//		// Face Direction
//		float moveDir = horizontal;
//		if (moveDir !=0) {
//			transform.eulerAngles = (moveDir>0)?Vector3.up * 180:Vector3.zero;
//		}
		
		// Set amount to move
		amountToMove.x = movementSpeed;
		amountToMove.y -= gravity * Time.deltaTime;
		patrollPhysics.Move(amountToMove * Time.deltaTime);


		
	}
}